package org.teziyou.ticket;

import org.teziyou.ticket.util.DbUtil;
import org.teziyou.ticket.web.IndexController;
import org.teziyou.ticket.web.TestController;
import org.teziyou.ticket.web.TicketController;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.ext.plugin.sqlinxml.SqlInXmlPlugin;
import com.jfinal.render.ViewType;

public class TicketConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		me.setDevMode(true);
		me.setEncoding("utf-8");
		me.setError404View("/error/404.html");
		me.setError500View("/error/500.html");
		me.setBaseViewPath("/WEB-INF/jsp/");
		me.setViewType(ViewType.JSP);
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/", IndexController.class);
		me.add("/test", TestController.class);
		me.add("/ticket", TicketController.class);
	}

	@Override
	public void configPlugin(Plugins me) {
		DbUtil.init(this, me);
		
		super.loadPropertyFile("memcached.txt");
		String memcachedUrl = super.getProperty("url");
		String memcachedPort = super.getProperty("port");
		MemcachedUtil.init(memcachedUrl, memcachedPort);
		
		me.add(new SqlInXmlPlugin());
	}

	@Override
	public void configInterceptor(Interceptors me) {
		
	}

	@Override
	public void configHandler(Handlers me) {
		me.add(new ContextPathHandler("basePath"));
	}

}
